package sk.fiit.icp.components;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.resource.ContextRelativeResource;

import sk.fiit.icp.calendar.view.HomePage;
import sk.fiit.icp.contactmanager.view.ContactManagerPage;
import sk.fiit.icp.eventmanager.view.EventManagerPage;
import sk.fiit.icp.note.view.NotePage;
import sk.fiit.icp.notemanager.view.NoteManagerPage;
import sk.fiit.icp.settings.view.SettingsPage;

public class HeaderSignedPanel extends Panel {

	public HeaderSignedPanel(String id) {
		super( id );
		add( new SignOutForm( "signOutForm" ) );
		final Link<Void> calendarLink = new Link<Void>( "calendarLink" ) {

			@Override
			public void onClick() {
				RequestCycle rc = RequestCycle.get();
				rc.setResponsePage( HomePage.class );
			}
		};
		calendarLink.add( new Image( "calendarImage", new ContextRelativeResource( "/images/Page/calendarButtonNot.png" ) ) );
		add( calendarLink );

		final Link<Void> eventLink = new Link<Void>( "eventLink" ) {

			@Override
			public void onClick() {
				RequestCycle rc = RequestCycle.get();
				rc.setResponsePage( EventManagerPage.class );
			}
		};
		eventLink.add( new Image( "eventImage", new ContextRelativeResource( "/images/Page/eventsButtonNot.png" ) ) );
		add( eventLink );

		final Link<Void> contactLink = new Link<Void>( "contactLink" ) {

			@Override
			public void onClick() {
				RequestCycle rc = RequestCycle.get();
				rc.setResponsePage( ContactManagerPage.class );
			}
		};
		contactLink.add( new Image( "contactImage", new ContextRelativeResource( "/images/Page/contactsButtonNot.png" ) ) );
		add( contactLink );

		final Link<Void> settingsLink = new Link<Void>( "settingsLink" ) {

			@Override
			public void onClick() {
				RequestCycle rc = RequestCycle.get();
				rc.setResponsePage( SettingsPage.class );
			}
		};
		settingsLink.add( new Image( "settingsImage", new ContextRelativeResource( "/images/Page/settingsButtonNot.png" ) ) );
		add( settingsLink );
		
		final Link<Void> notesLink = new Link<Void>( "notesLink" ) {

			@Override
			public void onClick() {
				RequestCycle rc = RequestCycle.get();
				rc.setResponsePage( NoteManagerPage.class );
			}
		};
		notesLink.add( new Image( "notesImage", new ContextRelativeResource( "/images/Page/ButtonNotes.png" ) ) );
		add( notesLink );
	}

	public class SignOutForm extends Form<Void> {

		public SignOutForm(String id) {
			super( id );
			SubmitLink submitLink = new SubmitLink( "signOutLink" );
			submitLink.add( new Image( "signOutImage", new ContextRelativeResource( "/images/Page/signOutButton.png" ) ) );
			add( submitLink );

		}

		@Override
		final public void onSubmit() {
			getSession().invalidateNow();
			setResponsePage( getApplication().getHomePage() );
		}
	}

}
